<template>
  <div class="login">
    <div class="container">
      <a href="/#/index">
        <img src="../../public/imgs/login-logo.png" alt="">
      </a>
    </div>
    <div class="wrapper">
      <div class="container">
        <div class="login-form">
          <h3>
            <span class="checked">账号登录</span>
            <span class="line">|</span>
            <span>扫码登录</span>
          </h3>
          <div class="input">
            <input type="text" placeholder="邮箱/手机号码/小米ID" v-model="username">
          </div>
          <div class="input">
            <input type="password" placeholder="密码" v-model="password">
          </div>
          <div class="btn-box">
            <a href="javascript:;" class="btn" @click="login">登录</a>
          </div>
          <div class="tips">
            <a href="javascript:;" @click="register">手机短信登录/注册</a>
          </div>
        </div>
      </div>
    </div>

    <div class="footer">
      <div class="footer-link">
        <a href="javascript:;">简体</a><span>|</span>
        <a href="javascript:;">繁体</a><span>|</span>
        <a href="javascript:;">English</a><span>|</span>
        <a href="javascript:;">隐私政策</a><span>|</span>
        <a href="javascript:;">常见问题</a>
      </div>
      <div class="copyright">Copyright © <span class="domain">2019 mi.51purse.com</span> All Rights Reserved</div>
    </div>
  </div>
</template>

<script>
  import {mapActions} from 'vuex';

  export default {
    name: "login",
    data() {
      return {
        username: '',
        password: '',
        userId: ''
      }
    },
    methods: {
      login() {
        let {username, password} = this;
        this.axios.post('/user/login', {
          username,
          password
        }).then((res) => {
          this.$cookie.set('userId', res.id, {expires: 'Session'});
          // this.$store.dispatch('saveUserName', res.username)
          this.saveUserName(res.username);
          this.$router.push({
            name: 'index',
            params: {
              from: 'login'
            }
          });
        })
      },
      ...mapActions(['saveUserName']),
      register() {
        this.axios.post('/user/register', {
          username: 'tianshow',
          password: 'tianshow',
          email: 'tianshow@tianshow.cn'
        }).then(() => {
          this.$message.success('注册成功！');
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .login > .container {
    height: 112px;

    a {
      display: inline-block;
      width: 230px;
      height: 112px;
    }
  }

  .wrapper {
    height: 576px;
    background: url("../../public/imgs/login-bg.jpg") no-repeat center;

    .container {
      height: 576px;

      .login-form {
        width: 410px;
        height: 510px;
        padding: 0 30px;
        box-sizing: border-box;
        background: #FFFFFF;
        position: absolute;
        right: 0;
        bottom: 29px;

        h3 {
          margin: 40px auto 49px;
          text-align: center;
          font-size: 24px;
          font-weight: 600;

          span {
            color: #666666;
          }

          span.line {
            margin: 0 34px;
          }

          .checked {
            color: #FF6600;
          }
        }

        .input {
          width: 348px;
          height: 50px;
          text-align: center;
          margin-bottom: 20px;

          input {
            padding-left: 18px;
            width: 100%;
            height: 100%;
            color: #999999;
            font-size: 14px;
            border: 1px solid #E5E5E5;
            box-sizing: border-box;
          }
        }

        .btn-box {
          margin-top: 10px;

          .btn {
            width: 348px;
            height: 50px;
            line-height: 50px;
            color: #FFFFFF;
            font-size: 16px;
            text-align: center;
          }
        }

        .tips {
          margin-top: 14px;

          a {
            color: #FF6600;
            font-size: 14px;
            text-align: left;
          }
        }
      }
    }
  }

  .footer {
    height: 80px;
    padding-top: 80px;
    text-align: center;

    .footer-link {
      a {
        color: #999999;
        display: inline-block;
      }

      span {
        margin: 0 10px;
      }

      margin-bottom: 20px;
    }

    .copyright {
      .domain {
        color: #FF6600;
      }
    }
  }
</style>

